<!DOCTYPE html>
<html>
<head>
    <title>FinData - 找回密码</title>
    <style>
        body {
            margin: 0;
            background: linear-gradient(135deg, #0a0a0a, #1a1a2e);
            font-family: 'Arial', sans-serif;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .forgot-container {
            width: 400px;
            background: rgba(18, 18, 18, 0.8);
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 0 30px rgba(138, 43, 226, 0.3);
        }
        
        .forgot-title {
            text-align: center;
            font-size: 2rem;
            margin-bottom: 30px;
            background: linear-gradient(90deg, #8a2be2, #00bfff);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        
        .input-group {
            margin-bottom: 25px;
        }
        
        .input-group label {
            display: block;
            margin-bottom: 8px;
            color: #e0e0e0;
        }
        
        .input-group input {
            width: 100%;
            padding: 12px;
            background: #121212;
            border: 1px solid #333;
            border-radius: 5px;
            color: #e0e0e0;
            font-size: 1rem;
        }
        
        .submit-btn {
            width: 100%;
            padding: 12px;
            background: linear-gradient(90deg, #8a2be2, #00bfff);
            border: none;
            border-radius: 5px;
            color: white;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .submit-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(138, 43, 226, 0.4);
        }
        
        .auth-links {
            text-align: center;
            margin-top: 20px;
            color: #e0e0e0;
        }
        
        .auth-link {
            color: #9d7cff;  /* 柔和的紫色 */
            text-decoration: none;
            font-size: 0.95rem;
            font-weight: 500;
            letter-spacing: 0.3px;
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            padding-bottom: 4px;
        }
        
        .auth-link:hover {
            color: #00e1ff;  /* 明亮的蓝色 */
        }
        
        .auth-link::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 1px;
            background: linear-gradient(90deg, #9d7cff, #00e1ff);
            transition: width 0.3s ease;
        }
        
        .auth-link:hover::after {
            width: 100%;
        }

        .notification {
            margin-top: 20px;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            display: none;
        }

        .success {
            background-color: rgba(0, 128, 0, 0.2);
            color: #4caf50;
        }

        .error {
            background-color: rgba(255, 0, 0, 0.2);
            color: #f44336;
        }
        
        .home-link {
            position: fixed;
            top: 20px;
            left: 20px;
            display: flex;
            align-items: center;
            color: #e0e0e0;
            text-decoration: none;
            font-size: 0.9rem;
            padding: 8px 12px;
            background: rgba(18, 18, 18, 0.7);
            border-radius: 5px;
            transition: all 0.3s;
        }
        
        .home-link:hover {
            background: rgba(138, 43, 226, 0.3);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        
        .home-icon {
            margin-right: 5px;
            width: 16px;
            height: 16px;
        }
        
        /* 版权信息样式 */
        .copyright-container {
            background-color: rgba(18, 18, 18, 0.8);
            padding: 15px;
            margin-top: 30px;
            text-align: center;
            border-top: 1px solid #333;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
        }
        
        .copyright {
            font-size: 12px;
            color: #666;
            text-align: center;
        }
    </style>
</head>
<body>
    <a href="/blank" class="home-link">
        <svg class="home-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M3 9L12 2L21 9V20C21 20.5304 20.7893 21.0391 20.4142 21.4142C20.0391 21.7893 19.5304 22 19 22H5C4.46957 22 3.96086 21.7893 3.58579 21.4142C3.21071 21.0391 3 20.5304 3 20V9Z" stroke="#e0e0e0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
            <path d="M9 22V12H15V22" stroke="#e0e0e0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
        返回主页
    </a>
    
    <div class="forgot-container">
        <h1 class="forgot-title">找回密码</h1>
        <form id="forgotForm">
            <div class="input-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>
            <div class="input-group">
                <label for="answer">安全问题：您最喜欢的城市是哪里？</label>
                <input type="text" id="answer" name="answer" required>
            </div>
            <div class="input-group">
                <label for="new_password">新密码</label>
                <input type="password" id="new_password" name="new_password" required>
            </div>
            <button type="submit" class="submit-btn">重置密码</button>
        </form>
        <div id="notification" class="notification"></div>
        <div class="auth-links">
            <a href="/login" class="auth-link">想起密码了？返回登录</a>
        </div>
    </div>

    <script>
        document.getElementById('forgotForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            const formData = new FormData(e.target);
            const notification = document.getElementById('notification');
            
            try {
                const response = await fetch('/api/forgot-password', {
                    method: 'POST',
                    body: formData
                });
                
                const result = await response.json();
                
                if (response.ok) {
                    notification.textContent = result.message;
                    notification.className = 'notification success';
                    notification.style.display = 'block';
                    
                    // 如果有重定向，2秒后跳转
                    if (result.redirect) {
                        setTimeout(() => {
                            window.location.href = result.redirect;
                        }, 2000);
                    }
                } else {
                    notification.textContent = result.detail || '密码重置失败';
                    notification.className = 'notification error';
                    notification.style.display = 'block';
                }
            } catch (error) {
                console.error('错误:', error);
                notification.textContent = '请求过程中发生错误';
                notification.className = 'notification error';
                notification.style.display = 'block';
            }
        });
    </script>
    
    <!-- 版权信息 -->
    <div class="copyright-container">
        <div class="copyright">
            © 2023-2024 FinData. All Rights Reserved. 保留所有权利。
        </div>
    </div>
</body>
</html>